//
//  LCSpirtualityTableViewCell.m
//  JKFuYinProject
//
//  Created by jiukuyinyue on 2017/9/18.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LCSpirtualityTableViewCell.h"

@interface LCSpirtualityTableViewCell ()

@property (nonatomic,strong) UIImageView *tempImageView;//
@property (nonatomic,strong) UILabel *nameLabel;//
@property (nonatomic,strong) UILabel *aboutLabel;//
@property (nonatomic,strong) UILabel *numLabel;//
@end

@implementation LCSpirtualityTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI{
    
    UIImageView * tempImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.size.width, self.size.height)];
    _tempImageView = tempImageView;
    tempImageView.backgroundColor = JK_CLEAR_COLOR;
    [self addSubview:tempImageView];
    
    [tempImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.size.width, self.size.height)];
    bgView.backgroundColor = [UIColor blackColor];
    bgView.alpha = 0.3;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(tempImageView);
    }];

    
    
    UILabel * nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, tempImageView.width, 54/2)];
    _nameLabel = nameLabel;

    nameLabel.textAlignment = NSTextAlignmentCenter;
    nameLabel.textColor = [UIColor whiteColor];
    [nameLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:26]];
    
    [self addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(50);
        make.height.equalTo(@(54/2));
        make.left.right.equalTo(tempImageView);
    }];
//简介
    UILabel * aboutLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 30, 40)];
    _aboutLabel = aboutLabel;
    aboutLabel.font = FONT_15;
    aboutLabel.textColor = [UIColor whiteColor];
    aboutLabel.numberOfLines = 0;
    aboutLabel.textAlignment = NSTextAlignmentCenter;

    [self addSubview:aboutLabel];

//更新
    UILabel * numLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,200, 20)];
    _numLabel = numLabel;
    numLabel.font = FONT_11;
    numLabel.textColor = [UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:1.0];
    numLabel.textAlignment = NSTextAlignmentCenter;
    numLabel.center = self.center;
    
    [self addSubview:numLabel];
    
    [aboutLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLabel.mas_bottom).offset(20);
        make.left.equalTo(self.mas_left).offset(20);
        make.right.equalTo(self.mas_right).offset(-20);
        make.height.offset(50);
    }];

    [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(aboutLabel.mas_bottom).offset(20);
        make.bottom.equalTo(tempImageView).offset(-20);
        make.centerX.equalTo(self);
    }];

}


-(void)setModel:(SpirtualityModel *)model{
    NSURL *url = [NSURL URLWithString:model.image];
    [_tempImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    NSString * ziliao = [model.content stringByReplacingOccurrencesOfString:@"<br/>" withString:@""];
    _aboutLabel.text = ziliao;
    _nameLabel.text = model.title;
    _numLabel.text = [NSString stringWithFormat:@"更新至 %@ 期", model.des];
    
    _model = model;

}
@end
